class Solution(object):
    def longestOnes(self, nums, k):
        left = 0
        right = 0
        n = len(nums)
        now_k = 0
        now_max = 0
        while right < n:
            if nums[right]:
                now_max = max(now_max, right - left + 1)
            else:
                now_k += 1
                if now_k > k:
                    while left <= right and nums[left]:
                        left += 1
                    left += 1
                    now_k = k
                now_max = max(now_max, right - left + 1)
            right += 1
        return now_max


data = Solution()
nums = [1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0]
k = 2
print(data.longestOnes(nums, k))
